<?php
 
class AppController extends Controller {
		
	var $components = array('Auth', 'Session', 'Acl', 'Email', 'RequestHandler');
	var $helpers = array('Html', 'Form', 'Session', 'Text', 'Js');
	
	var $uses = array('AppInformationElement');
	
function beforeFilter () {
		//Configure AuthComponent
		$this->Auth->authorize = 'actions';
		$this->Auth->userScope = array('Group.active' => true);
		$this->Auth->actionPath = 'controllers/';
		$this->Auth->flashElement = 'flash_failure';
		$this->Auth->allowedActions = array('display');
		$this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login');
		$this->Auth->autoRedirect = false;	
		
}
    
///////////////////////////////////////////////////////////////////////////// 
// Helper function for getting application content elements.   
function _getContentMsg($key = '') {
	
  $msg = $this->AppInformationElement->findByKey($key);
  if($msg && isset($msg['AppInformationElement']) 
  	 && isset($msg['AppInformationElement']['content'])) 
  {
		return strip_tags($msg['AppInformationElement']['content'],
				  "<h1><h2><h3><h4><p><img><br><a><span><strong><em><ul><li>");
	}
}

///////////////////////////////////////////////////////////////////////////// 
// Helper function for sending email.

function _sendEmailMsg($to, $subject, $message, $keys = array()) {
	$this->Email->reset();	
	$this->Email->smtpOptions = array(
		'host' => 'smtp.uoregon.edu'
	);

	$this->Email->to = $to;
	$this->Email->from = 'Graduate Secretary <gradsec@psych.uoregon.edu>';
	$this->Email->replyTo = 'Graduate Secretary <gradsec@psych.uoregon.edu>';
	$this->Email->bcc = array('gradsec@psych.uoregon.edu');
	$this->Email->subject = $subject;
	$this->Email->sendAs = 'text';
	$this->Email->template = 'simple_message';
	
	$this->set('message', $message);
	$this->set('keys', $keys);
	
	/* Set delivery method */
	$this->Email->delivery = 'smtp';
	/* Do not pass any args to send() */
	$ret = false;
	$ret = $this->Email->send();
	return $ret;
}

///////////////////////////////////////////////////////////////////////////////	

function _parseOptions($list = null) {

	$val = $this->_getContentMsg($list);
	$tmp = explode(',', $val);
	foreach($tmp as $val)
		$ret[trim($val)] = trim($val);
	return array_merge(array('' => '(Select Option)'), $ret);
}

} //end controller.
